package com.thoughtworks;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;


public class Main {

    private static int[] primeNumbers = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37,
                                         41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83,
                                         89, 97, 101, 103, 107, 109, 113, 127, 131, 137,
                                         139, 149, 151, 157, 163, 167, 173};


    public static void main(String[] args) {


	    oneAsterisk();
        System.out.println("\n");
        horizonatalLineNAsterisks(8);
        System.out.println("\n");
        verticalLineNAsterisks(3);
        System.out.println("\n");
        rightTriangleNAsterisks(3);
        System.out.println("\n");
        isoscelesTriangleNAsterisks(3);
        System.out.println("\n");
        diamondTriangleNAsterisks(5);
        System.out.println("\n");
        diamondTriangleWithNameNAsterisks(3);
        System.out.println("\n");
        FizzBuzz();
        System.out.println("\n");

        ArrayList<Integer> printList = generate(156);
        for (int i = 0; i < printList.size(); i++){
            System.out.print(printList.get(i) + ", ");
        }
    }

    private static void oneAsterisk(){
        System.out.print("*");
    }

    private static void horizonatalLineNAsterisks(int n){
        for (int i = 0; i < n; i++){
            System.out.print("*");
        }
    }

    private static void verticalLineNAsterisks(int n){
        for (int i = 0; i < n; i++){
            System.out.print("*\n");
        }
    }

    private static void rightTriangleNAsterisks(int n){
        for (int i = 1; i <= n; i++){
            for (int j = 0; j < i; j++) {
                System.out.print("*");
            }
            System.out.print("\n");
        }
    }

    private static void isoscelesTriangleNAsterisks(int n){
        int aster = 1;
        for (int i = 1; i <= n ; i++) {
            for (int j = n; j > i; j--) {
                System.out.print(" ");
            }
            for (int k = 0; k < aster; k++){
                System.out.print("*");
            }
            aster = aster + 2;
            System.out.print("\n");
        }
    }

    private static void diamondTriangleNAsterisks(int n){
        int aster = 1;
        for (int i = 1; i <= n ; i++) {
            for (int j = n; j > i; j--) {
                System.out.print(" ");
            }
            for (int k = 0; k < aster; k++){
                System.out.print("*");
            }
            aster = aster + 2;
            System.out.print("\n");
        }
        aster = aster - 4;
        for (int i = 1; i < n; i++) {
            for (int j = n; j > (n-i); j--){
                System.out.print(" ");
            }
            for (int k = 0; k < aster; k++){
                System.out.print("*");
            }
            aster = aster - 2;
            System.out.print("\n");
        }
    }

    private static void diamondTriangleWithNameNAsterisks(int n){
        int aster = 1;
        for (int i = 1; i <= n ; i++) {
            if (i == n){
                System.out.print("Bob");
                System.out.print("\n");
            } else {
                for (int j = n; j > i; j--) {
                    System.out.print(" ");
                }
                for (int k = 0; k < aster; k++) {
                    System.out.print("*");
                }
                aster = aster + 2;
                System.out.print("\n");
            }
        }
        aster = aster - 2;
        for (int i = 1; i < n; i++) {
            for (int j = n; j > (n-i); j--){
                System.out.print(" ");
            }
            for (int k = 0; k < aster; k++){
                System.out.print("*");
            }
            aster = aster - 2;
            System.out.print("\n");
        }
    }

    private static void FizzBuzz(){
        int n = 100;
        for (int i = 1; i <= 100; i++){
            if (i % 3 == 0 && i % 5 == 0){
                System.out.print("FizzBuzz");
                System.out.print("\n");
            } else if (i % 3 == 0) {
                System.out.print("Fizz");
                System.out.print("\n");
            } else if (i % 5 == 0){
                System.out.print("Buzz");
                System.out.print("\n");
            } else {
                System.out.print(i);
                System.out.print("\n");
            }

        }
    }

    private static ArrayList<Integer> generate(int n) {
        ArrayList<Integer> primeFromN = new ArrayList<Integer>();

        return generateHelper(primeFromN, n);
    }

    private static ArrayList<Integer> generateHelper (ArrayList<Integer> prime, int n){
        if (n == 1){
            return prime;
        } else {
            for (int i = 0; i < primeNumbers.length; i++) {
                if (n % primeNumbers[i] == 0) {
                    prime.add(primeNumbers[i]);
                    generateHelper(prime, n / primeNumbers[i]);
                    break;
                    }

                }
            }

        return prime;
    }

}
